<?php 
/*********************************************************
This file provides a list of available MO batches to send
to the bank blinded
*********************************************************/

/*********************************************************
includes
*********************************************************/
require_once 'config.inc';
require_once '_common.inc';
require_once '_customer.inc';
require_once '_db.inc';
require_once '_rsa.inc';
require_once '_ui.inc';

/*********************************************************
set the correct time zone to eliminate warnings in debug
date_default_timezone_set('America/New_York');

$script_tz = date_default_timezone_get();

if (strcmp($script_tz, ini_get('date.timezone'))){
    echo 'Script timezone differs from ini-set timezone.';
}
*********************************************************/

/*********************************************************
connect to db
*********************************************************/
$customer_conn = db_connect(CUSTOMER_DB_USER, CUSTOMER_DB_PASSWORD);

/*********************************************************
get available mo batches
*********************************************************/


$sql = "select m1.batch, m1.val, m1.c_cheat, m1.n from mo m1
	where not exists (
	select * from mo_detail_customer m2 where m2.batch = m1.batch
	and m2.bank_sig is not null and m2.spent = 0)";

$q_results = db_do_query($customer_conn, $sql);


/*********************************************************
close db connection
*********************************************************/
oci_close($customer_conn);

?>
<HTML>

<HEAD>
	<title>Select MO to give to Bank</title>
</HEAD>

<?php
ui_print_header('Customer - Select MO to give to Bank 2R_1');
echo <<<END
<FORM action="2R_2_BankGiveRandomR.php" method="post">
	<TABLE border="0">
	<tr><td width="190">Select Money Orders</td>
	<td width="20">:</td>
	<td>
END;

$mobatch = "test";
echo "<select name='batch'>\n";
echo "<option value=\"NULL\">Select Money Orders Available to Give to Bank</option>\n";

foreach($q_results as $qr) {
	$mob = $qr['BATCH'];
	if ($qr['C_CHEAT'] == 1) {
		$mov = "Quantity: " . $qr['N'] . ", Value: " . $qr['VAL'] . " - And 1 cheat";
	}
	else {
		$mov = "Quantity: " . $qr['N'] . ", Value: " . $qr['VAL'];
	}
	echo "<option value='$qr[BATCH]'>$mov</option>\n";
}

echo "</select>";

echo <<<END
	<TR>
		<TD colspan="2" align="center">
			<input type="submit" value="Give Money Orders to Bank">
		</TD>
		</TR>
	</TABLE>
</FORM>
END;

ui_print_footer(date('Y-m-d H:i:s'));
?>